import React, { Component } from 'react';
import { connect } from 'dva';
import { Tabs } from 'antd';

import Infomation from "./Information";
import Authentication from "./Authentication";
import Invoice from "./Invoice";
import Insurance from "./InsuranceBasic";
import { getComStatusAll,getCertificationData } from '../../../services/api';


import styles from './Company.less';

const { TabPane } = Tabs;


@connect(state => ({
  profile: state.profile,
}))

export default class Company extends Component {
  constructor(props, context) {
    super(props, context);
    this.state = {
      status: '0',//认证是否通过
    };
  }

  componentDidMount() {
    // fakeChartData1().then((data) => {
    //   console.log(data);
    // });
    /* const { dispatch } = this.props;
    dispatch({
      type: 'profile/fetchBasic',
    }); */
    // console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',this.child);
    getCertificationData({}).then((data) => {
      // console.log('公司状态公司状态公司状态' + data);
      if (data.data) {
        // console.log('123' + JSON.stringify(data.data));
        this.setState({
          status: data.data.authStatus,
        });
      }
    });
  }

  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        this.props.dispatch({
          type: 'form/submitRegularForm',
          payload: values,
        });
      }
    });
  };
  callback = (key) => {
    console.log(key);
    this.setState({ status: '0' });
  };

  changeStatus = () => {
    this.setState({ status: "1" });
  }

  render() {
    let showStatus = '';
    if (this.state.status === '0') {
      showStatus = (
        <div>认证申请<em className={styles.red}>(未认证)</em></div>
      );
    } else if (this.state.status === '1') {
      showStatus = (
        <div>认证申请<em className={styles.red}>(认证中)</em></div>
      );
    } else if (this.state.status === '2') {
      showStatus = (
        <div>认证申请<em className={styles.green}>(已认证)</em></div>
      );
    } else if (this.state.status === '3') {
      showStatus = (
        <div>认证申请<em className={styles.red}>(认证不通过)</em></div>
      );
    }else if(this.state.status === ''){
      showStatus = (
        <div>认证申请<em className={styles.red}>(未认证)</em></div>
      );
    }
    // console.log("xxxxxxxxxxxxxx",showStatus);
    return (
      <div className={styles.Company}>
        <Tabs tabBarStyle={{ marginLeft: 24, marginRight: 24 }} defaultActiveKey="1" >
          <TabPane tab="基础信息" key="1" >
            <Infomation />
          </TabPane>
          <TabPane tab={showStatus} key="2">
            <Authentication changeStatus={this.changeStatus} />
          </TabPane>
          <TabPane tab={<div>发票管理<em className={styles.green}>(已完善)</em></div>} key="3">
            <Invoice />
          </TabPane>
          <TabPane tab="企业保险" key="4">
            <Insurance props={this.props} styles={styles}/>
          </TabPane>
        </Tabs>
      </div>
    );
  }
}
